<template>
    <div id="content">
        <div class="inleft" @click="sub">-</div>
        <div class="incenter" v-text="count"></div>
        <div class="inright" @click="add">+</div>
    </div>
</template>
<script>
export default {
    props:['initCount','goodsid'],
    data() {
        return {
            count:1,
            resObj:{goodsid:0,type:'add'}
        }
    },
    created() {
        this.count = this.initCount;
    },
    methods: {
        sub(){
             this.count--;
            if(this.count <1){
                this.count = 1;
                return;
            }
               this.sentdata('sub');
            
            // this.count = this.count>1?(this.count--):1;
        },
        add(){
            this.count++;
            this.sentdata('add');
        },
        sentdata(type){
            this.resObj.type = type;
            this.resObj.goodsid = this.goodsid;
            this.$emit('carobjdataobj',this.resObj);
        }
    }
}
</script>
<style scoped>
#content{
    display: inline-block;
}
#content div{
		width: 40px;
		height: 25px;
		line-height: 25px;
		border: 1px solid #000;
		display: inline-block;
		text-align: center;
	}
</style>